// SegResultDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CStudyChinese.h"
#include "SegResultDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSegResultDlg dialog
#include "CStudyChineseDlg.h"

CSegResultDlg::CSegResultDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSegResultDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSegResultDlg)
	m_strSentence = _T("");
	//}}AFX_DATA_INIT
}


void CSegResultDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSegResultDlg)
	DDX_Text(pDX, IDC_EDIT1, m_strSentence);
	DDX_Control(pDX, IDC_EXPLORER1, m_BrowserSeg);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSegResultDlg, CDialog)
	//{{AFX_MSG_MAP(CSegResultDlg)
	ON_BN_CLICKED(IDC_PARSE, OnParse)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSegResultDlg message handlers

void CSegResultDlg::OnCancel() 
{
	this->ShowWindow(SW_HIDE);
}


void CSegResultDlg::Parse()
{
    OnParse();
}

void CSegResultDlg::OnParse() 
{
	UpdateData();
	static_cast<CCStudyChineseDlg*>(GetParent())->CSentSegment(m_strSentence,m_strSegResult);
	static_cast<CCStudyChineseDlg*>(GetParent())->CSentSegmentNoPos(m_strSentence,m_strSegResultNoPos);
	CreateShowSegFile();

	char strDir[1024];
	GetCurrentDirectory(1024,strDir);
	CString strHtmName(strDir);
	strHtmName+="\\ShowSeg.htm";
	this->m_BrowserSeg.Navigate(strHtmName,NULL,NULL,NULL,NULL);
}

void CSegResultDlg::CreateShowSegFile()
{
    CStdioFile tempFile;
	tempFile.Open("ShowSeg.htm",CFile::modeCreate|CFile::modeWrite);
	
	char Buffer1[1024],Buffer2[1024],Buffer3[1024];
	LoadString(::AfxGetInstanceHandle(),IDS_SEG_STRING1,Buffer1,1024);
	LoadString(::AfxGetInstanceHandle(),IDS_SEG_STRING2,Buffer2,1024);
	LoadString(::AfxGetInstanceHandle(),IDS_SEG_STRING3,Buffer3,1024);

	tempFile.WriteString(Buffer1);
	tempFile.WriteString(m_strSentence);
    tempFile.WriteString(Buffer2);
	tempFile.WriteString(m_strSegResultNoPos);
	tempFile.WriteString(Buffer3);
	tempFile.WriteString(this->m_strSegResult);
	tempFile.Close();
}
